package chapter11.section6;

//程序11-4a：银行业务的监控线程
public class Monitor extends Thread {

    private final Thread task;
    private final ThreadGroup clerks;
    private final Account account;

    public Monitor(Thread task, ThreadGroup clerks, Account account) {
        super();
        this.task = task;
        this.clerks = clerks;
        this.account = account;
    }

    @Override
    public void run() {
        while (true) {
            try {
                task.join();
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            clerks.interrupt();
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (clerks.activeCount() == 0) {
                break;
            }

        }
        System.out.println("账户最后的信息是：" + account);
    }
}
